package dian.qing.li.demo.security;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableFill;
import com.google.common.collect.Lists;
import com.pactera.generator.Generator;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

/**
 * @program: liqingdian
 * @description:
 * @author: EC_liqingdian
 * @create: 2020-06-03 10:01
 **/
public class GeneratorDemo {

    @Test
    public void create() {
        Generator instance = Generator.getInstance();
        AutoGenerator generator = instance.build();
        GlobalConfig globalConfig = generator.getGlobalConfig();
        globalConfig.setSwagger2(false);
        globalConfig.setOpen(false);
        DataSourceConfig dataSource = generator.getDataSource();
        dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/security-demo?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC");
        PackageConfig packageConfig = generator.getPackageInfo();
        packageConfig.setParent("dian.qing.li.demo");
        packageConfig.setModuleName("security");
        StrategyConfig strategyConfig = generator.getStrategy();
        strategyConfig.setTablePrefix("p_");
        // 乐观锁字段
        strategyConfig.setVersionFieldName("version");
        // 逻辑删除字段
        strategyConfig.setLogicDeleteFieldName("deleted");
        // 表填充字段
        ArrayList<TableFill> list = Lists.newArrayList();
        TableFill create = new TableFill("create_time", FieldFill.INSERT);
        list.add(create);
        TableFill update = new TableFill("update_time", FieldFill.INSERT_UPDATE);
        list.add(update);
        strategyConfig.setTableFillList(list);
        strategyConfig.setEntityLombokModel(true);
//        TemplateConfig template = generator.getTemplate();
//        template.setService("templates/service.java");
//        template.setServiceImpl("templates/serviceImpl.java");
        generator.execute();
    }

}
